﻿using Beauty.Net.MiniExcel.Core;
using System.ComponentModel.DataAnnotations;

namespace Beauty.Net.MiniExcel
{
    /// <summary>
    /// MiniExcel使用示例类
    /// 注意：此类仅用于演示，实际项目中应根据需求使用
    /// </summary>
    public class ExampleUsage
    {
        private readonly IMiniExcelService _miniExcelService;

        public ExampleUsage(IMiniExcelService miniExcelService)
        {
            _miniExcelService = miniExcelService;
        }

        /// <summary>
        /// 导出示例数据到Excel文件
        /// </summary>
        /// <param name="filePath">文件保存路径</param>
        public void ExportSampleData(string filePath)
        {
            var sampleData = GetSampleData();
            _miniExcelService.ExportToFile(sampleData, filePath, "用户数据");
        }

        /// <summary>
        /// 从Excel文件导入数据
        /// </summary>
        /// <param name="filePath">Excel文件路径</param>
        /// <returns>导入的用户数据列表</returns>
        public List<UserData> ImportUserData(string filePath)
        {
            return _miniExcelService.ImportFromFile<UserData>(filePath);
        }

        private List<UserData> GetSampleData()
        {
            return new List<UserData>
            {
                new UserData { Id = 1, Name = "张三", Age = 28, Email = "zhangsan@example.com", RegisterDate = new DateTime(2023, 1, 15) },
                new UserData { Id = 2, Name = "李四", Age = 32, Email = "lisi@example.com", RegisterDate = new DateTime(2023, 2, 10) },
                new UserData { Id = 3, Name = "王五", Age = 45, Email = "wangwu@example.com", RegisterDate = new DateTime(2023, 3, 5) }
            };
        }
    }

    /// <summary>
    /// 用户数据模型示例
    /// </summary>
    public class UserData
    {
        [Required]
        [Display(Name = "用户ID")]
        public int Id { get; set; }

        [Required]
        [Display(Name = "姓名")]
        public string Name { get; set; } = string.Empty;

        [Range(18, 100)]
        [Display(Name = "年龄")]
        public int Age { get; set; }

        [EmailAddress]
        [Display(Name = "电子邮箱")]
        public string Email { get; set; } = string.Empty;

        [Display(Name = "注册日期")]
        public DateTime RegisterDate { get; set; }
    }
}
